#include "DB.h"
#include "DBPageManager.h"
#include "DBIndexManager.h"

int drop(const char* tableName)
{
    int error;
    int fileid;
    char* tName = malloc(50);
    strcpy(tName, tableName);
    fileid = DBFileIsOpen(tName);
    if (fileid != -1) 
    {
        DBCloseFile(fileid);
    }  
    error = unlink(tName);
    if (error == -1)
    {
        printf("Drop table fail. Table with this name may not exist.\n");
        return -1;
    }
    strcat(tName, ".dbf");
    error = unlink(tName);
    if (error == -1)
    {
        printf("Drop table fail. Table with this name may not exist.\n");
        return -1;
    }
    printf("drop talbe %s.\n", tableName);
    return 0;
}

